import { getPageData, queryAllExportData } from '@/services/reportProgressApi';

export default {
  namespace: 'reportProgress',
  state: {
    data: {
      list: [],
      pagination: {},
      type: '',
    },
    netReportData: {
      list: [],
      pagination: {},
      type: '',
    },
  },

  effects: {
    /**
     * 获取列表数据
     * */
    *getPageData({ payload }, { call, put }) {
      const response = yield call(getPageData, payload);
      yield put({
        type: 'cb4getPageData',
        payload: response,
      });
    },

    /**
     * 点击导出列表信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *queryAllExportData({ payload }, { call, put }) {
      const response = yield call(queryAllExportData, payload);
      return response;
    },
  },

  reducers: {
    cb4getPageData(state, action) {
      let data = action.payload.data;
      if (!data) {
        data = {
          list: [],
          pagination: {},
          type: '',
        };
      }
      return {
        ...state,
        data: data,
      };
    },
  },
};
